package com.nCoV.EpidemicSurveillance.service;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import com.nCoV.EpidemicSurveillance.common.utils.SCPUtils;
import com.nCoV.EpidemicSurveillance.repository.AddCsvRepository;

/**
 * @author 张浩田
 * @date 2020年3月10日
 */
@Service
@Transactional
public class AddCsvService {
	
	@Autowired
	private AddCsvRepository addCsvRepository;
	
	/**
	 * 导入csv数据
	 * @return
	 */
	public Map<String, Object> addCsvData(){
		Map<String,Object> result = new HashMap<String, Object>();
		try{
			SCPUtils.upload();
			addCsvRepository.addPersonNodes();
			addCsvRepository.addPlaceNodes();
			addCsvRepository.addRelation();
			result.put("content", "success");
		}catch (Exception e) {
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
			result.put("content", "failed");
		}
	return result;
	}
}
